#ifndef ETCD_CLIENT_H
#define ETCD_CLIENT_H

#include <string>
#include <vector>
#include <memory>

struct EtcdResult {
    bool success;
    std::string value;
    std::string errorMessage;
    
    EtcdResult() : success(false) {}
    
    EtcdResult(bool s, const std::string& v = "", const std::string& err = "")
        : success(s), value(v), errorMessage(err) {}
};

// ETCD API客户端接口
class EtcdClient {
public:
    virtual ~EtcdClient() = default;
    
    // 获取指定键的值
    virtual EtcdResult get(const std::string& key) = 0;
    
    // 设置指定键的值
    virtual EtcdResult put(const std::string& key, const std::string& value, const std::string& leaseId = "") = 0;
    
    // 删除指定键
    virtual EtcdResult del(const std::string& key) = 0;
    
    // 获取指定前缀的所有键值对
    virtual EtcdResult getWithPrefix(const std::string& prefix) = 0;
    
    // 创建租约
    virtual EtcdResult leaseGrant(int ttl) = 0;
    
    // 撤销租约
    virtual EtcdResult leaseRevoke(const std::string& leaseId) = 0;
    
    // 续约租约
    virtual EtcdResult leaseKeepAlive(const std::string& leaseId) = 0;
    
    // 事务：比较并交换
    virtual EtcdResult txn(const std::string& key, const std::string& expected, bool compareEqual,
                          const std::string& targetKey, const std::string& targetValue, const std::string& leaseId = "") = 0;
    
    // 事务：原子比较并交换
    virtual EtcdResult txnCompareAndSwap(const std::string& key, const std::string& expected, 
                                        const std::string& newValue, bool compareEqual = true,
                                        const std::string& leaseId = "") {
        return txn(key, expected, compareEqual, key, newValue, leaseId);
    }
};

// 创建ETCD客户端的工厂函数
std::unique_ptr<EtcdClient> createEtcdClient(const std::string& endpoints);

#endif // ETCD_CLIENT_H 